package br.ufrn.acqua

class DocumentoController {

	def recuperar(long id){

		Documento documentInstance = Documento.get(id)

		response.setContentType("APPLICATION/OCTET-STREAM")
		//response.setHeader("Content-Disposition", "Attachment;Filename=\"${documentInstance.filename}\"")

		def fileInputStream = new ByteArrayInputStream(documentInstance.dados)
		def outputStream = response.getOutputStream()

		byte[] buffer = new byte[4096];
		int len;
		while ((len = fileInputStream.read(buffer)) > 0) {
			outputStream.write(buffer, 0, len);
		}

		outputStream.flush()
		outputStream.close()
		fileInputStream.close()
	}
}
